/*
 * @Author: sean_kei@163.com
 * @Date: 2022-08-03 13:19:53
 * @LastEditors: sean_kei@163.com
 * @LastEditTime: 2022-08-03 13:23:55
 */
package com.wxhandle.cleandemo.sso.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.scheduling.annotation.Async;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wxhandle.cleandemo.application.dto.identity.SysClaimDto;
import com.wxhandle.cleandemo.application.dto.identity.SysServiceDto;
import com.wxhandle.cleandemo.application.dto.identity.VueMenuDto;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@RestController
@RequestMapping("service")
public class SysServiceController {

    @Async
    @Transactional
    @PostMapping("menusync/{service}")
    public SysServiceDto syncVueMenu(@PathVariable("service") String service, @RequestBody List<VueMenuDto> menus){
        int i=0;
        SysServiceDto serviceDto = SysServiceDto.of(service, service, menus);
        List<SysClaimDto> claims= new ArrayList<>();
        for(VueMenuDto menu : menus) {
            if(!menu.getMeta().isHideInMenu())
                claims.add(SysClaimDto.of(menu, i++));
        }
        return serviceDto;
    }
}
